package com.shenyong.ladmin.controller;

import com.shenyong.ladmin.logConfig.Log;
import com.shenyong.ladmin.logConfig.OperationType;
import com.shenyong.ladmin.result.Page;
import com.shenyong.ladmin.service.ArticleService;
import com.shenyong.ladmin.entity.Article;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Create By:qiang
 * Date: 2019/11/28 18:07
 * 文件说明: ArticleController
 */
@RestController
@RequestMapping("/Article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @RequestMapping("listArticleAll")
    public Map<String, Object> listArticle(Page page) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("data", articleService.listArticle(page));
        map.put("count", articleService.getArticleCount(page));
        return map;
    }
    @RequiresAuthentication
    @Log(describe = "删除一篇文章",operationType= OperationType.DELETE)
    @RequestMapping("deleteArticle")
    public int deleteArticle(int article_id) {
        return articleService.deleteArricle(article_id);
    }
    @RequiresAuthentication
    @RequestMapping("accessArticle")
    public Article selectArticle(String article_id, String article_url) {
        Article article = new Article();
        int art_id = Integer.parseInt(article_id);
        article.setArticle_id(art_id);
        article.setArticle_url(article_url);
        List<Article> art = articleService.selectArticle(article);
        return art.get(0);
    }
    @RequestMapping("ArticleComment")
    public List<Article> getArticle(Article article) {
        return articleService.selectArticle(article);
    }
    @RequestMapping("selectArticleTop5")
    public List<Article> selectArticleTop5() {
        return articleService.selectArticleTop5();
    }
    @RequestMapping("AllArticle")
    public List<Article> AllArticle(Article article) {
        return articleService.AllArticle(article);
    }
}
